/**
 * @param {string} s
 * @return {string}
 */
var longestPalindrome = function (s) {
  let max = 0;
  let maxArr = [];
  if (!s) {
    return s;
  }
  const length = s.length;
  for (let left = 0; left < length; left++) {
    let right = length - 1;
    let finalRight = left;
    while (right !== left) {
      if (s.charAt(left) === s.charAt(right)) {
        finalRight = right;
      }
      right--;
    }
    const cha = finalRight - left;
    if (cha > max) {
      max = cha;
      maxArr = [left, finalRight];
    }
  }

  if (maxArr.length > 0) {
    return s.slice(maxArr[0], maxArr[1] + 1)
  } else {
    return s.charAt(max)
  }
};

const param = 'aacabdkacaa';
const res = longestPalindrome('ccc');
console.log(res);